/*******************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.   
  * @file     levetop.h
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-03
  * @brief    This file contains the interface information acquisition and 
  *           refresh of the UartTFT Application.
********************************************************************************/ 

/* public version: 2023.03.28 000 */ 

#ifndef _LEVETOP_H
#define _LEVETOP_H

#include "bsp.h"
#include "data.h"
#include "transport.h"
#include "tftlcd.h"
#include "function.h"
#include "tjpgd.h"

extern uint32_t ModBus_CMD_info_addr;	
extern uint32_t ModBus_CMD_info_sum;
extern uint32_t addr_index[];
extern uint32_t UI_version;
extern uint8_t encryption_key;
/***********/

void LT_ReadParam(void);
void Address_Index(void);
void Get_ModBus_CMD_info(void);

uint8_t Get_Touch_info(uint16_t id);            //get page info
uint8_t Get_date_variable_Id(uint16_t id);      //get page info
uint8_t Get_date_variable_Id_overlay(uint16_t id,uint16_t overlay1, uint16_t overlay_x,uint16_t overlay_y, uint16_t overlay_w, uint16_t overlay_h);
uint8_t Get_date_variable_Id_overlay_update(uint16_t id,uint16_t overlay1);
uint8_t update_date_variable_Id_overlay(uint16_t id);
uint8_t page_date_update(uint16_t id);                     //page refresh
uint8_t Get_date_variable_Id_Regular_update(uint16_t id);  //var refresh

uint8_t Get_Touch_info_download(uint16_t id);
uint8_t Get_date_variable_Id_download(uint16_t id);

extern uint8_t font_layflag;
void LT_getBackGround(uint16_t lcd_x,uint16_t lcd_y,uint16_t lcd_w,uint16_t lcd_h,uint8_t *p_buff,uint16_t lay_n);

/***********************************************************************************
* Function Name	: 
* Description	: Show a complete picture on the screen.
* Input			: - x,y: display coordinates of pictures on the screen
				  - Width,High,Addr: width,height and first address of the picture
* Output		: None
* Return		: None
************************************************************************************/
void LT268_TFT_ShowPicture    		(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint32_t flash_addr);
void LT268_TFT_ShowPicture_Png		(uint16_t x,uint16_t y,uint16_t Width,uint16_t High,uint32_t Addr);
void LT268_TFT_ShowPicture_Png_Pixel(uint16_t x,uint16_t y,uint16_t Width,uint16_t High,uint32_t Addr);
void LT268_TFT_ShowPicture_zip      (uint16_t x,uint16_t y,uint16_t Width,uint16_t High,uint32_t Addr);
void display_JPG					(uint16_t x,uint16_t y,uint16_t Width,uint16_t High,uint32_t Addr);
void LT_ShowPicture(uint16_t x, uint16_t y, uint16_t pic_w, uint16_t pic_h, uint32_t pic_addr, uint32_t pic_len, uint16_t format); 

/***************************************************************************************
* Function Name	: LT268_dispaly_CutPicture
* Description	: Show part of a picture on the screen.
* Input			:  - tft_x,tft_y: display coordinates of pictures on the screen
				   - cut_x,cut_y,cut_w,cut_h: display area of picture
				   - pic_w,pic_addr,pic_len,pic_flag: width,first address,len ang flag of the picture
* Output		: None
* Return		: None
****************************************************************************************/
void LT268_dispaly_CutPicture(
	uint16_t tft_x,uint16_t tft_y,
	uint16_t cut_x,uint16_t cut_y,uint16_t cut_w,uint16_t cut_h,
	uint16_t pic_w,uint32_t pic_addr,uint32_t pic_len,uint8_t pic_flag);


/******************************************************************************************************
* Function Name	: LT268_BG_to_Pure
* Description	: pure color to buffer.
* Input			:  - 
* Output		: None
* Return		: None
********************************************************************************************************/
uint8_t LT268_BG_to_Pure(
	uint16_t buff_x,uint16_t buff_y,uint16_t buff_w,uint8_t *m_Data,
	uint16_t cut_w, uint16_t cut_h,uint32_t color);


uint8_t LT268_BG_to_Pure_to_buff(
	uint16_t buff_x,uint16_t buff_y,uint16_t buff_w,uint8_t *m_Data,
	uint16_t cut_w, uint16_t cut_h,uint32_t color);

/******************************************************************************************************
* Function Name	: LT268_BG_to_buffer
* Description	: Background picture to buffer.
* Input			:  - 
* Output		: None
* Return		: None
********************************************************************************************************/
uint8_t LT268_BG_to_buffer(
	uint16_t buff_x,uint16_t buff_y,uint16_t buff_w,uint8_t *m_Data,
	uint16_t BG_x, uint16_t BG_y,uint16_t BG_w, uint16_t BG_h);

/******************************************************************************************************
* Function Name	: LT268_pic_to_buffer
* Description	: Capture a part of the image to the specified area of the buffer
* Input			:  - buff_x,buff_y,buff_w,m_Data: start coordinate on buffer,total width and first address of buffer
				   - pic_x,pic_y,pic_w,pic_addr: start coordinate on picture,pic_w and first address of the picture
				   - Width,High: Width and height of transmitted pictures
				   - Cflag: Cflag = ColorRGB565, Fill picture data to m_ Data.
						    Cflag = ColorARGB0565, Filter the black data in pic RGB565 data and fill it to m_ Data.
						    Cflag = ColorARGB4444, Mix the ARGB4444 data with the RGB565 data in buff and fill it to m_ Data.
						    Cflag = 3/4/5, Decoded the complete JPG picture to RGB565 data and stored in m_ Data.
						    Cflag = ColorJPG, Decoded zip picture data and stored in m_ Data.
* Output		: None
* Return		: None
********************************************************************************************************/
uint8_t LT268_pic_to_buffer(
uint16_t buff_x,uint16_t buff_y,uint16_t buff_w,uint8_t *m_Data,
uint16_t pic_x, uint16_t pic_y, uint16_t pic_w, uint32_t pic_addr,
uint16_t Width, uint16_t High,  uint8_t Cflag); 

/********************************************************************************
* Function Name	: LT268_buffer_to_TFT
* Description  	: Transfer the color data of the buffer to the screen.
* Input        	: - buff_x,buff_y,buff_w,m_Data:  start coordinate on buffer,total width and first address of buffer
				  - TFT_x,TFT_y: display start coordinate of screen
				  - Width,High: Width and height of pixels
* Output		: None
* Return		: None
*********************************************************************************/
uint8_t LT268_buffer_to_TFT(
uint16_t buff_x,uint16_t buff_y,uint16_t buff_w,uint8_t *m_Data,
uint16_t TFT_x, uint16_t TFT_y, uint16_t Width, uint16_t High);



void LT_CSS_PSRAM_Read_QPI_DMA_pic_to_buff(uint8_t *p ,uint16_t x , uint16_t y, uint16_t w , uint16_t h, uint16_t buff_w);

void LT_CSS_PSRAM_Write_QPI_DMA_pic(uint8_t *p, uint16_t x , uint16_t y, uint16_t w , uint16_t h, uint16_t buff_w);
void LT_CSS_PSRAM_to_TFT(uint32_t base_addr, uint16_t PSRAM_x , uint16_t PSRAM_y,uint16_t PSRAM_w,uint16_t TFT_x , uint16_t TFT_y, uint16_t w , uint16_t h);

//void LT_CSS_PSRAM_Flash_To_Psram_DMA_pic(qspi *psram_qspix, qspi *flash_qspix, uint16_t sck_dv, uint32_t psram_addr, uint32_t flash_addr, uint16_t w, uint16_t h, uint8_t flash_addr_type);
void LT_CSS_PSRAM_Flash_To_Psram_DMA_pic(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t buff_w, uint32_t flash_addr,uint8_t flash_addr_type);
void LT_CSS_PSRAM_Flash_To_Psram_DMA_cut_pic(uint16_t buff_x, uint16_t buff_y, uint16_t buff_w, uint16_t pic_x, uint16_t pic_y, uint16_t pic_w, uint32_t flash_addr, uint16_t w,uint16_t h);
void LT_CSS_PSRAM_Write_16bit_QPI_DMA_FillColor(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color,uint16_t buff_w);
uint16_t LT_CSS_PSRAM_Read_Point(uint16_t x, uint16_t y, uint16_t buff_w);
void LT_CSS_PSRAM_Write_Point(uint16_t x, uint16_t y, uint16_t color, uint16_t buff_w);

void LT168_TFT_ShowPicture_PSRAM(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint32_t flash_addr);
void LT168_TFT_ShowPicture_PSRAM_Png(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint32_t flash_addr);
void LT168_TFT_ShowPicture_PSRAM_Png_Pixel(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint32_t flash_addr);


#endif	/* _LEVETOP_H */
